package com.yanqu.road.server.cmd.coldRoom;

import com.yanqu.road.pb.coldRoom.ColdRoomProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.ColdRoomModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_COLDROOM_ONEKEY_HARVEST, desc = "一键领取")
public class OneKeyHarvestCmd extends AbstractCommand {

    private long harvest;
    private long nowTime;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        nowTime = System.currentTimeMillis();
        harvest = player.getModule(ColdRoomModule.class).oneKeyHarvest(nowTime);
        if (harvest == 0) {
            ret = GameErrorCode.E_COLDROOM_NOT_HARVEST;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        ColdRoomProto.OneKeyHarvestRespMsg.Builder respMsg = ColdRoomProto.OneKeyHarvestRespMsg.newBuilder();
        respMsg.setRet(ret);
        if(0 == ret){
            respMsg.setHarvest(harvest);
            respMsg.setRestoreTime(nowTime/1000);
        }
        player.sendPacket(Protocol.U_COLDROOM_ONEKEY_HARVEST, respMsg);
    }
}
